package cn.edu.ctbu.dp01.service;

import cn.edu.ctbu.dp01.dao.TeacherRepository;
import cn.edu.ctbu.dp01.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

import static org.springframework.data.jpa.domain.AbstractPersistable_.id;

@Service
public class TeacherService {
    @Autowired
    public TeacherRepository teacherRepository;
    public List<Teacher> getAll() {
        return teacherRepository.findAll();
    }
    public Teacher findById(int id) {
        return teacherRepository.findById(id).get();
    }
    public List<Teacher> findByName(String name) {
        return teacherRepository.findByNameLike(name);
    }
    //public List<Teacher> findByNameAndPassword(String password,String name) {
        //return teacherRepository.findByNameAndPassword(name, password);
    //}
    public void insert(Teacher teacher) {
        teacherRepository.save(teacher);
    }
    public Teacher add(Teacher teacher) {
        return teacherRepository.save(teacher);
    }
    public Teacher update(Teacher teacher) {
        return teacherRepository.save(teacher);
    }
    public void delete(Integer id) {
        teacherRepository.deleteById(id);
    }
}